using System.Collections.Generic;
using UnityEngine;

public class MobTypesManager : MonoBehaviour
{
	public static MobTypesManager instance;

	public List<MobGroup> mobGroups;

	private void Awake()
	{
		GameModeChange();
		settings.gameModeChange += GameModeChange;
	}

	private void GameModeChange()
	{
		if (settings.offlineMode && instance == null)
		{
			instance = this;
			InitGroup();
		}
	}

	private void OnDestroy()
	{
		settings.gameModeChange -= GameModeChange;
		instance = null;
	}

	private void InitGroup()
	{
		Object[] array = Resources.LoadAll("MobGrops");
		Object[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			GameObject gameObject = (GameObject)array2[i];
			string text = gameObject.name;
			GameObject gameObject2 = Object.Instantiate(gameObject);
			gameObject2.transform.parent = base.transform;
			gameObject2.name = text;
			mobGroups.Add(gameObject2.GetComponent<MobGroup>());
		}
	}

	public void InitSectors()
	{
		SectorMobManager[] allMobsSectors = MobSpawnController.instance.allMobsSectors;
		foreach (SectorMobManager sectorMobManager in allMobsSectors)
		{
			for (int j = 0; j < sectorMobManager.mobGroups.Count; j++)
			{
				foreach (MobGroup mobGroup in mobGroups)
				{
					if (sectorMobManager.mobGroups[j].group.gameObject.name == mobGroup.gameObject.name)
					{
						MobSectorGroupParams value = default(MobSectorGroupParams);
						value.group = mobGroup;
						value.percentChance = sectorMobManager.mobGroups[j].percentChance;
						sectorMobManager.mobGroups[j] = value;
					}
				}
			}
		}
	}
}
